home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / fbm12s.lha / fbsharp.c < prev    next >
C/C++ Source or Header  |  1994-07-18  |  3KB  |  112 lines

  1. /*****************************************************************
  2.  * fbsharp.c: FBM Release 1.2 07-Apr-93 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989-1993 by Michael Mauldin.  Permission is granted
  5.  * to use this file in whole or in part for any purpose, educational,
  6.  * recreational or commercial, provided that this copyright notice
  7.  * is retained unchanged.  This software is available to all free of
  8.  * charge by anonymous FTP and in the UUNET archives.
  9.  *
  10.  * fbsharp.c: Sharpen an image by using a Laplacian edge enhancement
  11.  *
  12.  * USAGE
  13.  *    % fbsharp [ flags ] arguments
  14.  *
  15.  * EDITLOG
  16.  *    LastEditDate = Mon Jun 25 00:04:40 1990 - Michael Mauldin
  17.  *    LastFileName = /usr2/mlm/src/misc/fbm/fbsharp.c
  18.  *
  19.  * HISTORY
  20.  * 07-Apr-93  Michael Mauldin (mlm) at Carnegie-Mellon University
  21.  *    Added -J switch
  22.  *
  23.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  24.  *    Package for Release 1.0
  25.  *
  26.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  27.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  28.  *
  29.  * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  30.  *    Created.
  31.  *****************************************************************/
  32.  
  33. # include <stdio.h>
  34. # include <math.h>
  35. # include "fbm.h"
  36.  
  37. # define USAGE "fbsharp [ -SF ] beta < 8bit > 8bit"
  38.  
  39. #ifndef lint
  40. static char *fbmid =
  41. "$FBM fbsharp.c <1.2> 07-Apr-93 (C) 1989-1993 by Michael Mauldin, source \
  42. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  43. #endif
  44.  
  45. main (argc, argv)
  46. char *argv[];
  47. { int w, h, k;
  48.   double beta = 2.0;
  49.   FBM input, output;
  50.   int outtype = DEF_8BIT;
  51.  
  52.   /* Get the options */
  53.   while (--argc > 0 && (*++argv)[0] == '-')
  54.   { while (*++(*argv))
  55.     { switch (**argv)
  56.       { 
  57.     case 'A':    outtype = FMT_ATK; break;
  58.     case 'B':    outtype = FMT_FACE; break;
  59.     case 'F':    outtype = FMT_FBM; break;
  60.     case 'G':    outtype = FMT_GIF; break;
  61.     case 'I':    outtype = FMT_IFF; break;
  62.     case 'J':    outtype = FMT_JPEG; break;
  63.     case 'L':    outtype = FMT_LEAF; break;
  64.     case 'M':    outtype = FMT_MCP; break;
  65.     case 'P':    outtype = FMT_PBM; break;
  66.     case 'R':    outtype = FMT_RLE; break;
  67.     case 'S':    outtype = FMT_SUN; break;
  68.     case 'T':    outtype = FMT_TIFF; break;
  69.     case 'X':    outtype = FMT_X11; break;
  70.     case 'Z':    outtype = FMT_PCX; break;
  71.     default:        fprintf (stderr, "%s\n", USAGE);
  72.                         exit (1);
  73.       }
  74.     }
  75.   }
  76.  
  77.   /* Clear the memory pointers so alloc_fbm won't be confused */
  78.   input.cm  = input.bm  = (unsigned char *) NULL;
  79.   output.cm = output.bm = (unsigned char *) NULL;
  80.  
  81.   /* Read the image and sharpen it */
  82.   if (read_bitmap (&input, (char *) NULL))
  83.   {
  84.     if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  85.     { fprintf (stderr,
  86.            "Can't handle images with %d bits and %d physbits per pixel\n",
  87.            input.hdr.bits, input.hdr.physbits);
  88.       exit (1);
  89.     }
  90.  
  91.     /* Argument is amount of sharpening */
  92.     if (argc > 0)        { beta = atof (argv[0]); }
  93.  
  94.     /* Determine output height & width (oh*ow <= size) */
  95.     h = input.hdr.rows;
  96.     w = input.hdr.cols;
  97.     k = input.hdr.planes;
  98.  
  99.     fprintf (stderr,
  100.          "Sharpen \"%s\", beta %1.3lf [%dx%dx%d]\n",
  101.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  102.          beta, w, h, k);
  103.  
  104.     /* Sharpen the image using a digitial Laplacian */
  105.     if (sharpen_fbm (&input, &output, beta) &&
  106.         write_bitmap (&output, stdout, outtype))
  107.     { exit (0); }
  108.   }
  109.   
  110.   exit (1);
  111. }
  112.